#ifndef __HAND_MODEL__
#define __HAND_MODEL__
#include "PrimaryGeometry.h"
#include "Particle_Const.h"
#include <vector>

#define KINECT_DEPTH_NOMINAL_FOCAL_LENGTH_IN_PIXELS         (571.4f)   // Based on 640x480 pixel size.
#define KINECT_DEPTH_NOMINAL_DIAGONAL_FOV                   (70.0f)
#define KINECT_DEPTH_NOMINAL_HORIZONTAL_FOV                 (58.5f)
#define KINECT_DEPTH_NOMINAL_VERTICAL_FOV                   (45.6f)

#define KINECT_COLOR_NOMINAL_FOCAL_LENGTH_IN_PIXELS         (531.15f)   // Based on 640x480 pixel size.
#define KINECT_COLOR_NOMINAL_INVERSE_FOCAL_LENGTH_IN_PIXELS (1.83e-3f)
#define KINECT_COLOR_NOMINAL_DIAGONAL_FOV                   ( 73.9f)
#define KINECT_COLOR_NOMINAL_HORIZONTAL_FOV                 ( 62.0f)
#define KINECT_COLOR_NOMINAL_VERTICAL_FOV                   ( 48.6f)

#define PIXEL_PER_MM										(1.4285f)

#define N_SLICES 24
#define N_STACKS 12

enum FingerType{
	HM_FINGER_DEFAULT,
	HM_FINGER_THUMB,
	HM_FINGER_1,
	HM_FINGER_2,
	HM_FINGER_3,
	HM_FINGER_LITTLE,
};

struct handBone
{
	//Eigen::Vector3f root_join;  // 
	float length;
	float radius1;
	float radius2;
	GLuint vertexBuf;
	GLuint vertexDisplayList;
};

// Lop bieu dien ngon tay
class HmFinger
{
public:
	FingerType type;
	handBone bone[3];
	HmFinger();
	~HmFinger();
	void setDefaultParameter();
	void setFingerParameter(int bone_index,float radious1,float radious2,float length);
};

class HandModel
{
public:
	HandModel(void);
	~HandModel(void);

	float handScale;
	/* There are 26 DOFs on a Hand */
	Eigen::Vector3f wirst_rotation;//+3 DOFs
	//Eigen::Vector3f wirst_position;//+3 DOFs
	HmFinger finger_thumb;//+4 DOFs - 2 in bone 1, 1 each other bones
	HmFinger finger_1;//+4 DOFs
	HmFinger finger_2;//+4 DOFs
	HmFinger finger_3;//+4 DOFs
	HmFinger finger_little;//+4 DOFs

	double wirst_position[3];
	double * handDOFs;

	GLuint vertexFinger_Thumb[3];
	GLuint vertexFinger_1[3];
	GLuint vertexFinger_2[3];
	GLuint vertexFinger_3[3];
	GLuint vertexFinger_Little[3];
	void generateConeBuffer(GLuint & buf,GLfloat botRadius,GLfloat topRadius,GLfloat height);
	void generateFingersBuffer();

	void generateVertexBuffers();
	double *sint;
	double *cost;

	double lastTime;
	unsigned int frame;

	// buffer for capture depth OPENGL
	GLfloat * buffer;

	GLuint sphereVertexBuf;
	GLuint sphereDisplayList;
	void generateSphereBuffer();
	void drawSphere(GLfloat radius);
	void drawElipse(GLfloat radiusX,GLfloat radiusY,GLfloat radiusZ);

	GLuint cylinderVertexBuffer;
	GLuint cylinderDisplayList;
	void generateCylinderBuffer();
	void drawCylinder(GLfloat radius,GLfloat height);
	void drawElipCylinder(GLfloat radiusX,GLfloat radiusZ,GLfloat height);

	void drawHandBone(handBone bone,double rotation);
	void drawFinger(HmFinger hm_finger);

	void drawPalm(float width, float height, float depth);

	void drawHand();
	void drawPalmAndFiveFingers();
};

#endif __HAND_MODEL__